package com.system.provider;

import com.am.ui.grid.AbstractBaseGridProvider;
import com.system.uitls.CommonUtil;
import com.system.uitls.SearchFilter;
import java.util.Map;

public class ApproveHistoryProvider extends AbstractBaseGridProvider
{
  public String generateSql(Map<String, Object> map)
  {
    String startTime = CommonUtil.nullToEmptyString(map.get("startTime"));
    String endTime = CommonUtil.nullToEmptyString(map.get("endTime"));
    String type = CommonUtil.nullToEmptyString(map.get("type"));
    String status = CommonUtil.nullToEmptyString(map.get("status"));
    String place = CommonUtil.nullToEmptyString(map.get("place"));

    StringBuffer sql = new StringBuffer("SELECT t2.id,t1.create_time,t1.user_name,t1.place,t1.campus,t1.notes,t2.type,t2.approve_result FROM sys_out_storage t1,sys_approve t2 WHERE t1.id=t2.out_storage_id AND t2.status=1 AND t2.approve_user_id=:currentUserId ");

    if (!"".equals(startTime)) {
      sql.append(" AND t1.create_time>=:startTime");
    }

    if (!"".equals(endTime)) {
      sql.append(" AND t1.create_time<=:endTime");
    }

    if (!"".equals(type)) {
      sql.append(" AND t2.type=:type");
    }

    if (!"".equals(status)) {
      sql.append(" AND t1.status=:status");
    }

    if (!"".equals(place)) {
      sql.append(" AND t1.place=:place");
    }

    sql.append(SearchFilter.getSearchSql(map, null));
    setParamMap(map);

    return sql.toString();
  }
}